package de.tabuma.pm.projectnavigation.view;

import de.tabuma.pm.projectnavigation.entity.ProjectNavigation;
import de.tabuma.lib.tabumaview;
import java.io.PrintWriter;
import java.util.*;
import java.util.logging.*;
import de.tabuma.pm.*;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author alefen
 */
public class update extends tabumaview {

    private static final Logger log = Logger.getLogger(update.class.getName());

    public update(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    @Override
    public void processRequest(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {

        if(request.getAttribute(constants.ProjectNavigationUpdate)!=null) {

            String update = "Update";
            String name = "Navigation Name";
            String mainnavigation = "Mainnavigation";

            ProjectNavigation pn = (ProjectNavigation) request.getAttribute(constants.ProjectNavigation);

            out.println("<form action=\""+this.getServlet()+"#"+constants.ProjectNavigationA+"\">");
            out.println(name);
            out.println("<input type=\"text\" name=\""+constants.ProjectNavigationName+"\" value=\""+pn.getName()+"\"/>");
            out.println("<select name=\""+constants.ProjectNavigationHeadId+"\">");

            List<ProjectNavigation> pnList = (List<ProjectNavigation>) request.getAttribute(constants.ProjectNavigationList);
            out.println("<option value=\"0\">"+mainnavigation+"</option>");
            for(int i=0;i<pnList.size();i++) {
                ProjectNavigation pn1 = pnList.get(i);
                if(pn1.getId().intValue()==pn.getNavigationId()) {
                    out.println("<option value=\""+pn1.getId()+"\" selected>"+pn1.getName()+"</option>");
                }
                else {
                    out.println("<option value=\""+pn1.getId()+"\">"+pn1.getName()+"</option>");
                }
            }

            out.println("</select>");
            Enumeration enu = this.getParameter().keys();
            while(enu.hasMoreElements()) {
                String key = (String) enu.nextElement();
                String value = (String) this.getParameter().get(key);
                out.println("<input type=\"hidden\" name=\""+key+"\" value=\""+value+"\"/>");
            }
            out.println("<input type=\"hidden\" name=\""+constants.ProjectNavigationId+"\" value=\""+pn.getId()+"\"/>");
            out.println("<input type=\"hidden\" name=\""+constants.ProjectNavigationUpdate1+"\" value=\"true\"/>");
            out.println("<input type=\"submit\" class=\"smallbutton\" name=\"update\" value=\""+update+"\"/>");
            out.println("</form>");
        }

    }



}
